#include <stdio.h> 
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <map>
#include <queue>

using namespace std; 

#define SN 21
#define RN 6

struct pair_s {
	char org[SN]; 
	char tgt[SN]; 
}; 

struct bfs_node_s {
	char str[SN]; 
	int  steps; 
}; 

struct pair_s ab; 
struct pair_s rules[RN]; 
int nr_rules; 

queue<struct bfs_node_s *> bfs_q; 
map<string, int> bfs_map; 

void trans(const struct pair_s *rule, const char *org, 
	const char *loc, char *res)
{
	char *d=res; 
	const char *s1, *s2; 
	for(s1=org; s1!=loc; s1++, d++) {
		*d = *s1; 
	}
	for (s2=rule->org; *s2; s2++) {
		s1++; 
	}
	for (s2=rule->tgt; *s2; s2++, d++) {
		*d = *s2; 
	}
	for (;*s1; s1++, d++) {
		*d = *s1; 
	}
	*d = '\0'; 
}

int bfs(void)
{
	struct bfs_node_s *node, *nn; 
	int i, ret; 
	char *p, *loc; 
	if (!strcmp(ab.org, ab.tgt))
		return 0; 
	node = (struct bfs_node_s *)malloc(sizeof(struct bfs_node_s)); 
	assert(node); 
	strcpy(node->str, ab.org); 
	node->steps = 0; 
	bfs_q.push(node); 
	while(!bfs_q.empty()) {
		node = bfs_q.front(); 
		//printf("\nnode:%p, str: %s, steps: %d\n", node, node->str, node->steps); 
		bfs_q.pop(); 
		for (i=0; i<nr_rules; i++) {
			p = node->str; 
			while(*p) {
				p = strstr(p, rules[i].org); 
				//printf("rule[%d]: '%s'-->'%s', match: '%s'\n", i, rules[i].org, rules[i].tgt, p); 
				if (!p) {
					break; 
				}
				loc = p;
				p++; 
				nn = (struct bfs_node_s *)malloc(sizeof(struct bfs_node_s)); 
				assert(nn); 
				nn->steps = node->steps + 1; 
				trans(&rules[i], node->str, loc, nn->str); 
				//printf("nn:%p, trans res: '%s', nn->steps=%d\n", nn, nn->str, nn->steps); 
				if (!strcmp(nn->str, ab.tgt)) {
					ret = nn->steps; 
					free(nn); 
					//printf("mached, return it\n"); 
					return ret; 
				} else if (nn->steps>=10) {
					//printf("drop it, too many steps, line=%d\n", __LINE__); 
					free(nn); 
				} else if(bfs_map.count(nn->str)==1) {
					//printf("drop it, have seen, line=%d\n", __LINE__); 
					free(nn); 
				} else {
					//printf("push it, line=%d\n", __LINE__); 
					bfs_map[nn->str] = 1; 
					bfs_q.push(nn); 
				}
			}
		}
		free(node); 
	}
	return -1; 
}

int main()
{
	int ret; 
	//freopen("p1032_2.in", "r", stdin); 
	//freopen("p1032.out", "w", stdout); 
	cin>>ab.org>>ab.tgt; 
	while(cin>>rules[nr_rules].org>>rules[nr_rules].tgt) {
		nr_rules ++; 
	}
	ret = bfs(); 
	if (ret>=0) 
		printf("%d\n", ret); 
	else 
		printf("NO ANSWER!\n"); 
	return 0; 
}


